package tgc.edu.tms.entity;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.tms.custom.BaseEntity;
@Entity
public class TbMenu extends BaseEntity<Integer>{
	private String name;
	private String url;
	private Integer idx1;
	@JsonIgnore
	private TbMenu parent;
	private Permission role=new Permission();//权限
	private Integer type;		//菜单种类
	@JsonIgnore
	private List<TbMenu> children=new ArrayList<>();
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getUrl() {
		return url;
	}
	public void setUrl(String url) {
		this.url = url;
	}

	public Integer getIdx1() {
		return idx1;
	}
	public void setIdx1(Integer idx1) {
		this.idx1 = idx1;
	}
	@ManyToOne
	@CreatedBy
	public TbMenu getParent() {
		return parent;
	}
	public void setParent(TbMenu parent) {
		this.parent = parent;
	}
	
	@Transient
	public Integer getParentId() {
		return parent==null?null:parent.getId();
	}
	@ManyToOne
	@CreatedBy
	public Permission getRole() {
		return role;
	}
	public void setRole(Permission role) {
		this.role = role;
	}
	public TbMenu() {
		super();
	}
	public TbMenu(Integer id) {
		super(id);
	}
	
	@OneToMany(cascade=CascadeType.ALL,mappedBy="parent")
	@OrderBy(value="idx1")
	public List<TbMenu> getChildren() {
		return children;
	}
	public void setChildren(List<TbMenu> children) {
		this.children = children;
	}
	public Integer getType() {
		return type;
	}
	public void setType(Integer type) {
		this.type = type;
	}
	
	
}
